<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="shortcut icon" href="<!--{eval echo register_static('img/touch-icon-57x57.png');}-->">

    <title>粉粉管理系统</title>

    <!-- Bootstrap core CSS -->
    <link href="<!--{eval echo register_static('css/bootstrap.min.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/bootstrap-reset.css');}-->" rel="stylesheet">

    <!--Animation css-->
    <link href="<!--{eval echo register_static('css/animate.css');}-->" rel="stylesheet">

    <!--Icon-fonts css-->
    <link href="<!--{eval echo register_static('assets/font-awesome/css/font-awesome.css');}-->" rel="stylesheet" />
    <link href="<!--{eval echo register_static('assets/ionicon/css/ionicons.min.css');}-->" rel="stylesheet" />

    <link href="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.css');}-->" rel="stylesheet">

    <!-- Plugins css -->
    <link href="<!--{eval echo register_static('assets/modal-effect/css/component.css');}-->" rel="stylesheet">

    <!-- DataTables -->
    <link rel="stylesheet" href="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.css" rel="stylesheet');}-->" />

    <!-- Custom styles for this template -->
    <link href="<!--{eval echo register_static('css/style.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/helper.css');}-->" rel="stylesheet">

    <!-- My styles for this template -->
    <link href="<!--{eval echo register_static('css/common.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('assets/timepicker/bootstrap-timepicker.min.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('assets/timepicker/bootstrap-datepicker.min.css');}-->" rel="stylesheet">

</head>

<body id="mybody">

<!-- Aside Start-->
<!--{template admin_v2/leftside}-->
<!-- Aside Ends-->


<!--Main Content Start -->
<section class="content">

    <!-- Header -->
    <!--{template admin_v2/header}-->
    <!-- Header Ends -->


    <!-- Page Content Start -->
    <!-- ================== -->

    <div class="wraper container-fluid diary-topics">

        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default" style="overflow: auto;">
                    <div class="panel-heading">
                        <h3 class="panel-title">设备型号管理</h3>
                    </div>
                    <div class="panel-body">
                        <div class="row" style="margin-bottom: 10px">
                            <div class="col-md-9 col-sm-9 col-xs-9">
                                <!-- Search -->
                                <div class="form-inline">
                                    <div style="display: inline-block; padding-right: 20px">筛选</div>
                                    <!--<div class="form-group">-->
                                        <!--<select class="form-control myChoose" name="type">-->
                                            <!--<option value="no">类型(全部)</option>-->
                                            <!--<option value="launch">开机页面</option>-->
                                            <!--<option value="banner">社区Banner</option>-->
                                            <!--<option value="home_banner">首页Banner</option>-->
                                            <!--<option value="wisdom">每日一语</option>-->
                                            <!--<option value="recommend_banner">推荐banner</option>-->
                                        <!--</select>-->
                                    <!--</div>-->
                                    <div class="form-group">
                                        <select class="form-control myChoose" name="status">
                                            <option value="no">全部</option>
                                            <option value="0">使用中</option>
                                            <option value="1">待审核</option>
                                        </select>
                                    </div>
                                    <div class="form-group pageCon">

                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-3 col-xs-3">
                                <button class="btn btn-info myAdd"><i class="ion-plus-round"></i> 新增</button>
                                <!--<button class="btn btn-info myFind"><i class="ion-search"></i> 查找</button>-->
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12 col-sm-12 col-xs-12">
                                <table id="datatable" class="table table-striped table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th>id</th>
                                        <th>状态</th>
                                        <th>小尾巴显示</th>
                                        <th>系统</th>
                                        <th>厂商(品牌)</th>
                                        <th>小尾巴显示</th>
                                        <th>设备</th>
                                        <th>版本</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>

                                    <tbody id="tbody">

                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row" style="margin-top: 15px">
                            <div class="form-group pageCon"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- Page Content Ends -->
    <!-- ================== -->

    <div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">

    </div><!-- /.modal -->


    <!-- Footer Start -->
    <!--{template admin_v2/footer}-->
    <!-- Footer Ends -->



</section>
<!-- Main Content Ends -->

<!--template start-->
<script type="text/template" id="tableCon">
    {{#.}}
    <tr>
        <td><label class="label label-success">{{{id}}}</label></td>
        <td>{{{deviceStatusNO2Text status}}}</td>
        <td>{{{pname}}}</td>
        <td>{{{os}}}</td>
        <td>{{{manufacturer}}}</td>
        <td>{{{market_name}}}</td>
        <td>{{{codename}}}</td>
        <td>{{{model}}}</td>
        <td>
            <div class="btn-group btn-group-sm">
                <button type="button" class="btn btn-danger myDelete" data-id="{{{id}}}">删除</button>
                {{{deviceStatusOpBtn status id}}}
            </div>
        </td>
    </tr>
    {{/.}}
</script>

<script type="text/template" id="editModal">
    {{#.}}
    <form>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="25%">类别</th>
                    <th width="75%">内容</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>uid</td>
                    <td>
                        <input type="text" name="uid" class="form-control" placeholder="" value="{{{uid}}}" disabled style="width: 150px" min="0">
                    </td>
                </tr>
                <tr>
                    <td>开始时间</td>
                    <td >
                        <div class="form-inline">
                            <div class="form-group">
                                <input type="text" name="start_time" class="form-control timepicker2"  placeholder="" value="{{{dateConv start_time}}}" style="width: 180px">
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>结束时间</td>
                    <td >
                        <div class="form-inline">
                            <div class="form-group">
                                <input type="text" name="end_time" class="form-control timepicker2" placeholder="" value="{{{dateConv end_time}}}" style="width: 180px">
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>操作</td>
                    <td style="text-align: center">
                        <button type="button" class="btn btn-info myEditPost" data-id="{{{id}}}">完成</button>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
    {{/.}}
</script>

<script type="text/template" id="addModal">
    <form>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="25%">类别</th>
                    <th width="75%">内容</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>小尾巴显示</td>
                    <td>
                        <input type="text" name="name" class="form-control" placeholder="" value="" >
                    </td>
                </tr>
                <tr>
                    <td>厂商品牌</td>
                    <td>
                        <input type="text" name="manufacturer" class="form-control" placeholder="" value="" >
                    </td>
                </tr>
                <tr>
                    <td>系统</td>
                    <td>
                        <input type="text" name="os" class="form-control" placeholder="android 或者 ios" value="" >
                    </td>
                </tr>
                <tr>
                    <td>设备</td>
                    <td>
                        <input type="text" name="codename" class="form-control" placeholder="" value="" >
                    </td>
                </tr>
                <tr>
                    <td>版本</td>
                    <td>
                        <input type="text" name="model" class="form-control" placeholder="" value="" >
                    </td>
                </tr>
                <tr>
                    <td>操作</td>
                    <td style="text-align: center">
                        <button type="button" class="btn btn-info myAddPost" data-id="{{{id}}}">添加</button>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
</script>


<script type="text/template" id="myFind">
    <form>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="25%">类别</th>
                    <th width="75%">内容</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>uid</td>
                    <td>
                        <input type="text" name="uid" class="form-control" placeholder="" value="" style="width: 150px" min="0">
                    </td>
                </tr>
                <tr>
                    <td>操作</td>
                    <td style="text-align: center">
                        <button type="button" class="btn btn-info myAddFind">查找</button>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
</script>
<!--template end-->


<!-- js placed at the end of the document so the pages load faster -->
<script src="<!--{eval echo register_static('js/jquery.js');}-->"></script>
<script src="<!--{eval echo register_static('js/bootstrap.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/pace.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/wow.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/jquery.nicescroll.js');}-->" type="text/javascript"></script>
<script src="<!--{eval echo register_static('js/jquery.app.js');}-->"></script>

<script src="<!--{eval echo register_static('js/handlebars-v4.0.5.js');}-->"></script>
<script src="<!--{eval echo register_static('js/handlebars-helper.js');}-->"></script>
<script src="<!--{eval echo register_static('layer/layer.js');}-->"></script>
<script src="<!--{eval echo register_static('laypage/laypage.js');}-->"></script>
<script src="<!--{eval echo register_static('laydate/laydate.js');}-->"></script>

<script src="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/datatables/dataTables.bootstrap.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.init.js');}-->"></script>

<!-- Modal-Effect -->
<script src="<!--{eval echo register_static('assets/modal-effect/js/classie.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/modal-effect/js/modalEffects.js');}-->"></script>

<script type="text/javascript">
    $(document).ready(function() {

        //编译模板
        var tp_tableCon = Handlebars.compile($('#tableCon').html());
        var tp_editModal = Handlebars.compile($('#editModal').html());
        var tp_addModal = Handlebars.compile($('#addModal').html());
        var tp_myFindModal = Handlebars.compile($('#myFind').html());

        $('.myChoose').change(function () {
            _Where_.page = 1;
            var name = $(this).attr('name');
            switch (name){
                case 'type':
                    $(this).val() != 'no' ?  _Where_.type = $(this).val() : _Where_.type = undefined;
                    break;
                case 'status':
                    $(this).val() != 'no' ?  _Where_.status = $(this).val() : _Where_.status = undefined;
                    break;
            }
            RequestList();
        });

        $('.myAdd').click(function () {
            var html = tp_addModal();
            layer.open({
                type: 1,
                title: '新增机型',
                closeBtn: 1,
                area:['400px', '500px'],
                shadeClose: true,
                content: html
            });
        });

        $('.myFind').click(function () {
            var html = tp_myFindModal();
            layer.open({
                type: 1,
                title: '搜索uid',
                closeBtn: 1,
                area:['400px', '300px'],
                shadeClose: true,
                content: html
            });
        });

        $(document).off('change', 'form select[name="type"]').on('change', 'form select[name="type"]', function () {
            var val = $(this).find("option:selected").val();
            var form = $(this).parents('form');
            if (val=='wisdom'){
                form.find('.endtimeinput').hide();
            }else{
                form.find('.endtimeinput').show();
            }
            if(val=='recommend_banner'){
                var action = 'pinksns://diary/info?uid=4366393&bodyId=566665031';
                $('form textarea[name="action_url"]').html(action);
            }
            if(val=='banner'){
                var action = 'pinksns://group/topic?tid=1810707&uid=4&gid=16';
                $('form textarea[name="action_url"]').html(action);
            }
        });

        $(document).off('click', '.myDelete').on('click', '.myDelete', function () {
            var id = $(this).data('id');
            if (!id)return;
            layer.confirm('确定删除设备id: '+id+' ？', {icon: 3, title:'提示'}, function(i){
                var index = layer.load();
                $.post(
                    '/admin.php?ac=vip&op=dvdelete',
                    {id:id},
                    function (r) {
                        layer.close(index);
                        if(r.result){
                            layer.closeAll();
                            RequestList();
                            layer.msg('删除成功', {icon: 1});
                        }else{
                            layer.msg('操作失败', {icon: 0});
                        }
                    }
                );
            });
        });

        var actionData="";
        $(document).on('blur','form textarea[name="action_url"]',function(){
           actionData=$(this).val();
        });
        $(document).off('click', '.myAddPost').on('click', '.myAddPost', function () {
            var form = $(this).parents('form');
            var param = form.serialize();
            layer.confirm('确定添加此设备 ？', {icon: 3, title:'提示'}, function(i){
                var index = layer.load();
                $.post(
                        '/admin.php?ac=vip&op=dvadd',
                        param,
                        function (r) {
                            layer.close(index);
                            if(r.result){
                                layer.closeAll();
                                RequestList();
                                layer.msg('添加成功', {icon: 1});
                            }else{
                                layer.msg('操作失败', {icon: 0});
                            }
                        }
                );
            });
        });

        $(document).off('click', '.myFlushDayPost').on('click', '.myFlushDayPost', function () {
            var dates = $(this).parents('form').find('input[name="day"]').val().trim();
            if (!dates)return;
            layer.load();
            $.post(
                    '/admin.php?ac=activity2&op=flushday',
                    {dates:dates},
                    function (r) {
                        layer.closeAll();
                        if(r._code == 1){
                            RequestList();
                            layer.msg('更新成功', {icon: 1});
                        }else{
                            layer.msg(r._msg, {icon: 0});
                        }
                    }
            );

        });

        $(document).off('click', '.myEditPost').on('click', '.myEditPost', function () {
            var id = $(this).data('id');
            layer.load();
            var param = $(this).parents('form').serialize();
            $.post(
                    '/admin.php?ac=vip&op=editdetail&id=' + id,
                    param,
                    function (r) {
                        layer.closeAll();
                        if(r._code == 1){
                            RequestList();
                            layer.msg('更新成功', {icon: 1});
                        }else{
                            layer.msg(r._msg, {icon: 0});
                        }
                    }
            );

        });

        $(document).off('click', '.myEdit').on('click', '.myEdit', function () {
            var id = $(this).data('id');
            if (!id)return;
            layer.confirm('确定通过设备id: '+id+' ？', {icon: 3, title:'提示'}, function(i){
                var index = layer.load();
                $.post(
                    '/admin.php?ac=vip&op=dvedit',
                    {id:id, status:0},
                    function (r) {
                        layer.close(index);
                        if(r.result){
                            layer.closeAll();
                            RequestList();
                            layer.msg('操作成功', {icon: 1});
                        }else{
                            layer.msg('操作失败', {icon: 0});
                        }
                    }
                );
            });
        });

        $(document).off('click', '.timepicker2').on('click', '.timepicker2', function () {
            laydate({
                format: 'YYYY-MM-DD hh:mm:ss',
                istime: true
            });
        });

        $(document).off('click', '.timepicker3').on('click', '.timepicker3', function () {
            laydate({
                format: 'YYYYMMDD',
                festival: true,
                istime: false
            });
        });

        $(document).off('click', '.showImg').on('click', '.showImg', function () {
            layer.tips('<img src="'+$(this).attr('src')+'" />', $(this), {
                tips: [2, '#fff'],
            });
        });

        $(document).off('change', '.actionChange').on('change', '.actionChange', function () {
            var NO = $(this).val();
            ActionChangeSelect(NO);
        });

        _Where_ = {page:1};
        //请求数据列表数据
        var RequestList = function () {
            where = _Where_;
            if(typeof where == 'undefined')where = {};
            var index = layer.load();
            $.post(
                    '/admin.php?ac=vip&op=dvlist',
                    where,
                    function (r) {
                        if (r._code == 1){
                            var html = tp_tableCon(r.result);
                            $('#tbody').html(html);
                            laypage({
                                cont: $('.pageCon'), //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
                                pages: 100, //通过后台拿到的总页数
                                curr: _Where_.page || 1, //当前页
                                jump: function(obj, first){ //触发分页后的回调
                                    if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
                                        _Where_.page = obj.curr;
                                        RequestList();
                                    }
                                }
                            });
                        }else{
                            layer.msg(r._msg, {icon: 0});
                        }
                        layer.close(index);
                    }
            );
        }
        RequestList();

    });

</script>
</body>
</html>
